package com.napenalki.toto.domain;

import static org.junit.Assert.assertEquals;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

public abstract class DomainTestFixture {

    protected Validator validator = null;
    
    public DomainTestFixture() {
        ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
        validator = factory.getValidator();
    }

    protected void assertErrors(int numberOfErrors) {
        assertEquals(numberOfErrors, validator.validate(getTestObject()).size());
    }

    protected abstract Object getTestObject();

    protected User populateUser(User user) {
        user.setUserName("userName");
        user.setPassword("testPassword");
        user.setEmail("user@test.com");
        user.setDisplayName("test");
        user.setPoints(100);
        user.setPredictions(new ArrayList<Prediction>());
        
        return user;
    }
    
    protected Team populateTeam(Team team) {
        team.setName("test");
        team.setFlag(new File(".\\flag.jpeg"));
        team.setGroup("B");
        team.setPlayersList(Arrays.asList("test test"));
        
        return team;
    }
    
    protected Match populateMatch(Match match) {
        match.setId(1);
        match.setDate(new Date());
        match.setLocked(false);
        match.setStage(Stages.FINAL);
        match.setTeam1Name("team1");
        match.setTeam2Name("team2");
        match.setResult("1:1");
        
        return match;
    }
    
    protected SpecialEvent populateSpecialEvent(SpecialEvent event) {
        event.setId(1);
        event.setDate(new Date());
        event.setLocked(false);
        event.setEventType(SpecialEvents.CHAMPION);
        event.setResult("CSKA");
        
        return event;
    }
    
    protected Prediction populatePrediction(Prediction prediction, User user, Event event) {
        prediction.setId(1);
        prediction.setUser(user);
        prediction.setEvent(event);
        prediction.setPrediction("1:1");
        
        return prediction;
    }
}
